package com.bjx.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bjx.common.core.domain.R;
import com.bjx.common.core.domain.group.Update;
import com.bjx.system.domain.query.DictTypeQuery;
import com.bjx.system.domain.vo.DictTypeVO;
import com.bjx.system.service.IDictTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 字典类型
 * @author: liushuai
 * @date: 2022/8/15
 */
@RequestMapping("/dict/type")
@Tag(name = "字典类型控制器")
@RestController
public class DictTypeController {

    @Autowired
    private IDictTypeService dictTypeService;

    /**
     * 分页查询字典类型列表
     * @param dictTypeQuery
     * @return: com.bjx.common.core.domain.R<com.baomidou.mybatisplus.core.metadata.IPage<com.bjx.system.domain.vo.DictTypeVO>>
     * @Author: liushuai
     * @Date: 2022/8/15
     */
    @Operation(summary = "分页查询字典类型列表")
    @GetMapping("listDictTypePage")
    public R<IPage<DictTypeVO>> listDictTypePage(DictTypeQuery dictTypeQuery) {
        IPage<DictTypeVO> page = dictTypeService.listDictTypePage(dictTypeQuery);
        return R.success(page);
    }

    /**
     * 根据字典类型id查询字典类型
     * @param dictTypeId
     * @return: com.bjx.common.core.domain.R<com.bjx.system.domain.vo.DictTypeVO>
     * @Author: liushuai
     * @Date: 2022/9/6 22:06
     */
    @Operation(summary = "根据字典类型id查询字典类型")
    @GetMapping("selectDictTypeByDictTypeId")
    public R<DictTypeVO> selectDictTypeByDictTypeId(@RequestParam Long dictTypeId){
        DictTypeVO vo = dictTypeService.selectDictTypeByDictTypeId(dictTypeId);
        return R.success(vo);
    }




    /**
     * 根据字典类型id删除字典类型
     * @param dictTypeId
     * @return: com.bjx.common.core.domain.R
     * @Author: liushuai
     * @Date: 2022/9/6 21:04
     */
    @Operation(summary = "根据字典类型id删除字典类型")
    @GetMapping("deleteDictTypeByDictTypeId")
    public R deleteDictTypeByDictTypeId(@RequestParam Long dictTypeId){
        dictTypeService.deleteDictTypeByDictTypeId(dictTypeId);
        return R.successMsg("删除字典成功");
    }

   /**
    * 新增字典类型
    * @param dictTypeVO
    * @return: com.bjx.common.core.domain.R
    * @Author: liushuai
    * @Date: 2022/8/15
    */
   @Operation(summary = "新增字典类型")
   @PostMapping("insertDictType")
   public R insertDictType(@RequestBody @Validated DictTypeVO dictTypeVO){
      dictTypeService.insertDictType(dictTypeVO);
      return R.successMsg("新增字典类型成功");
   }

    /**
     * 修改字典类型
     * @param dictTypeVO
     * @return: com.bjx.common.core.domain.R
     * @Author: liushuai
     * @Date: 2022/8/15
     */
    @Operation(summary = "修改字典类型")
    @PostMapping("updateDictType")
    public R updateDictType(@RequestBody @Validated(Update.class) DictTypeVO dictTypeVO){
        dictTypeService.updateDictType(dictTypeVO);
        return R.successMsg("修改字典类型成功");
    }





}
